package cn.xie.wrench.ty.wrench.starter.design.framework.tree;

import lombok.Getter;
import lombok.Setter;

/**
 * @author: xiaoxie
 * create: 2025-05-14 14:43
 * @BelongsProject: ty-wrench
 * @BelongsPackage: cn.xie.wrench.ty.wrench.starter.design.framework.tree
 * description: 策略路由抽象类
 */
public abstract class AbstractStrategyRouter<T, D, R> implements StrategyMapper<T, D, R>, StrategyHandler<T, D, R> {

    @Getter
    @Setter
    protected StrategyHandler<T, D, R> defaultStrategyHandler = StrategyHandler.DEFAULT;

    public R router(T requestParameter, D dynamicContext) throws Exception {
        StrategyHandler<T, D, R> strategyHandler = get(requestParameter, dynamicContext);
        if(null != strategyHandler) {
            return strategyHandler.apply(requestParameter, dynamicContext);
        }
        return defaultStrategyHandler.apply(requestParameter, dynamicContext);
    }

}

